import React, { useState } from 'react';
import EstimateModal from './EstimateModal';
import { TaskOperateType } from '../../../../utils';
import { fetchOperateDetails } from '../../../containers/MyTaskInfoModal/util';

const EstimateDetail = ({ EstimateDetailRef }) => {
    const [modalData, setModalData] = useState();
    const [modalVisible, setModalVisible] = useState(false);
    const [modalType, setModalType] = useState('');
    // const [modalTableData, setModalTableData] = useState([]);
    const props = {
        modalVisible,
        setModalVisible,
        modalData,
        modalType // 类型
    };
    const showEstimateModal = async (id, recId, OperateType) => {
        const resultData = await fetchOperateDetails(id, recId);
        setModalData(resultData);
        // 公用组件
        if (OperateType === TaskOperateType.ESTIMATION) {
            // 估算
            setModalType('ESTIMATION');
        } else if (OperateType === TaskOperateType.LAUNCH_ESTIMATION) {
            // 发起估算
            setModalType('LAUNCH_ESTIMATION');
        } else if (OperateType === TaskOperateType.RESUME_ESTIMATION) {
            // 重估
            setModalType('RESUME_ESTIMATION');
        } else if (OperateType === TaskOperateType.LAUNCH_RESUME_ESTIMATION_APPLY) {
            // 发起重估申请
            setModalType('LAUNCH_RESUME_ESTIMATION_APPLY');
        } else {
            console.log('没有该类型');
        }
        setModalVisible(true);
    };

    React.useImperativeHandle(EstimateDetailRef, () => ({
        showEstimateModal
    }));

    return (
        <>
            <EstimateModal {...props} />
        </>
    );
};

export default EstimateDetail;
